// featurePackage/pages/companyWxService/companyWxService.js
const app = getApp();
import {
  SERVICE_URL,
  SERVICE_ID,
} from "../../../service/base_service"
import {
  randomServiceCode
} from "../../../service/jb_mine_service"
import {
  queryNewPersonCoupons,
} from "../../../service/jb_coupon_service"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    qrCode: 'https://images.jiabao19.com/common/testqw.jpg',
    cWxUrl: "https://work.weixin.qq.com/gm/916d2d7a5d156ca3b2b6b2a2c0aabbd8",
    couponOne: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getRandomServiceCode();
    this.queryNewPersonCoupons();
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  pushToService() {
    wx.openCustomerServiceChat({
      extInfo: { url: SERVICE_URL },
      corpId: SERVICE_ID,
      success(res) { },
      fail(err) {
        console.log('调用失败:', err);
      }
    })
  },
  //获取随机客服企微二维码
  getRandomServiceCode() {
    wx.showLoading();
    randomServiceCode().then(res => {
      wx.hideLoading()
      if (res.code == 200) {
        if (res.data) {
          this.setData({
            qrCode: res.data
          })
        }
      }
    }).catch(err => {
      wx.hideLoading()
    })
  },

  queryNewPersonCoupons() {
    queryNewPersonCoupons().then(res => {
      console.log("JJLog:新人券:" + JSON.stringify(res));
      if (res.data.list && res.data.list.length > 0) {
        this.setData({
          couponOne: res.data.list.slice(0, 3)
          //couponOne: [...res.data.list, ...res.data.list, ...res.data.list]
        })
      }
      // this.setData({
      //   couponOne: res.data.list || []
      // })
      // if (res.data && res.data.list && res.data.list.length > 0) {
      //   let arr = res.data.list;
      //   let newPersonMoney = 0;
      //   arr.forEach(i => {
      //     newPersonMoney = newPersonMoney + parseInt(i.money)
      //   })
      //   this.setData({
      //     newPersonMoney: newPersonMoney
      //   })
      // }
    }).catch(err => {
      console.error("JJLog:queryNewPersonCoupons:", err);
    })
  },
  pushToLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },

})